//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Exception Handling Application Block
//===============================================================================

using System;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace EntLibContrib.ExceptionHandling.Configuration
{
	/// <summary>
	/// Represents the configuration data for an error code.
	/// </summary>
	public class ErrorCodeEntryData : NamedConfigurationElement
	{
		#region Fields
		private static AssemblyQualifiedTypeNameConverter typeConverter = new AssemblyQualifiedTypeNameConverter();
		private const string ErrorCodePropertyName = "errorCode";
		private const string WrapExceptionTypeNamePropertyName = "wrapExceptionTypeName";
		private const string ExceptionMessagePropertyName = "exceptionMessage";
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="ErrorCodeEntryData"/> class.
		/// </summary>
		public ErrorCodeEntryData()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ErrorCodeEntryData"/> class.
		/// </summary>
		/// <param name="name">The name of the element.</param>
		public ErrorCodeEntryData(string name)
			: base(name)
		{
		}
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the type of the replacement exception.
		/// </summary>
		/// <value>The type of the wrap exception.</value>
		public Type WrapExceptionType
		{
			get { return (Type)typeConverter.ConvertFrom(WrapExceptionTypeName); }
			set { WrapExceptionTypeName = typeConverter.ConvertToString(value); }
		}

		/// <summary>
		/// Gets or sets the error code.
		/// </summary>
		/// <value>The error code.</value>
		[ConfigurationProperty(ErrorCodePropertyName)]
		public int ErrorCode
		{
			get { return (int)this[ErrorCodePropertyName]; }
			set { this[ErrorCodePropertyName] = value; }
		}

		/// <summary>
		/// Gets or sets the name of the wrap exception type.
		/// </summary>
		/// <value>The name of the wrap exception type.</value>
		[ConfigurationProperty(WrapExceptionTypeNamePropertyName)]
		public string WrapExceptionTypeName
		{
			get { return (string)this[WrapExceptionTypeNamePropertyName]; }
			set { this[WrapExceptionTypeNamePropertyName] = value; }
		}

		/// <summary>
		/// Gets or sets the exception message.
		/// </summary>
		/// <value>The exception message.</value>
		[ConfigurationProperty(ExceptionMessagePropertyName)]
		public string ExceptionMessage
		{
			get { return (string)this[ExceptionMessagePropertyName]; }
			set { this[ExceptionMessagePropertyName] = value; }
		}
		#endregion
	}
}
